using System.Collections;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;

namespace OpenWaves.Web.Controls
{
    public class ChildNodesPlaceHolder : NodesPlaceHolderBase
    {
        public override IEnumerable<T> GetNodes<T>(IEnumerable<T> children)
        {
            return children;
        }
    }

    public abstract class NodesPlaceHolderBase : PlaceHolder
    {
        public abstract IEnumerable<T> GetNodes<T>(IEnumerable<T> children);

        public Control ItemsContainer
        {
            get { return (Control)this.GetChildrenRecursively().OfType<ItemsPlaceHolder>().SingleOrDefault() ?? this; }
        }
    }

    public class NodesPlaceHolder : NodesPlaceHolderBase
    {
        public IEnumerable DataSource { get; set; }

        public override IEnumerable<T> GetNodes<T>(IEnumerable<T> children)
        {
            return Enumerable.Cast<T>(this.DataSource);
        }
    }
}